const express = require( 'express' );

const port = 8080 ;
const app = express();

app.use( express.static( 'public' ) );

app.all( '/response' , (req,resp)=>{
    // let url = '/test.html' ;
    let url = 'http://www.kaifamiao.com' ;
    //resp.redirect( url );

    resp.status(302);
    resp.setHeader( 'location' , url );
    resp.send();
});

app.get( '/play' , (req,resp) => {
    console.log( req.method , req.originalUrl );
    resp.setHeader( 'content-disposition' , `inline` );
    resp.sendFile( 'D:/uploads/1011PM02-NODEJS-用fs读写文件.mp4' );
} );

app.get( '/download' , (req,resp) => {
    console.log( req.method , req.originalUrl );
    //resp.setHeader( 'content-type' , 'application/octet-stream' );
    //resp.setHeader( 'content-disposition' , `attachment; filename="test.mp4"` );
    let pathname = 'D:/uploads/1011PM02-NODEJS-用fs读写文件.mp4' ;
    resp.attachment( pathname ); // 设置响应头
    resp.sendFile( pathname ); // 通过响应体发送数据
} );


app.listen( port );